package com.pay.config;

import javax.sql.DataSource;

import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;


/**
 * @Description: MariaDB数据源配置
 * @see: MariaDBConfig 此处填写需要参考的类
 * @version 2016年8月25日 上午11:05:39
 * @author jian.cao
 */
@Configuration
@PropertySource("classpath:/application.properties")
public class MariaDBConfig {

	private static final Logger logger = LoggerFactory.getLogger(MariaDBConfig.class);
	/**
	 * 生产
	 *
	@Value("${com.pay.boss.dsName}")
	private String bossDsName;


	@Bean(name= "bossDataSource" ,destroyMethod = "close")
	public DataSource bossDataSource() {
		long l = System.currentTimeMillis();
		logger.info("dsName = {} , {}",bossDsName,l);
		C3p0PooledDataSource ds = new C3p0PooledDataSource();
		ds.setDataSourceName(bossDsName);
		return ds;
	}
	 */

	/**
	 * 开发配置
	 * * 
	*/
	@Value("${boss.db.driverClassName}")
	private String bossDriverClassName;
    @Value("${boss.db.url}")
    private String bossUrl;
    @Value("${boss.db.username}")
    private String bossUsername;
    @Value("${boss.db.password}")
    private String bossPassword;

    @Bean(name= "bossDataSource" ,destroyMethod = "close")
	public DataSource bossDataSource() {
		PoolProperties poolProperties = new PoolProperties();
		poolProperties.setDriverClassName(bossDriverClassName);
		poolProperties.setUrl(bossUrl);
		poolProperties.setUsername(bossUsername);
		poolProperties.setPassword(bossPassword);
		return new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
	}

    
}
